﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HHDBUtility;
using System.Data;
using System.Data.SqlClient;
namespace HHCommon
{
    public class FrontCommon
    {
        #region //获取页面标题关键字内容
        Help help = new Help();
        /// <summary>
        /// 获取页面标题关键字内容
        /// </summary>
        /// <param name="PageName">页面名称</param>
        /// <param name="CacheKey">缓存关键字</param>
        /// <param name="i">设置缓存时间</param>
        /// <returns></returns>
        public string GetPageKeys(string PageName, string CacheKey, int i)
        {
            StringBuilder PageKeyWord = new StringBuilder();
            try
            {
                DataSet ds;
                if (System.Web.HttpContext.Current.Cache[CacheKey] == null)
                {
                    //数据缓存
                    ds = GetKeyWordData(PageName.Remove(0, PageName.LastIndexOf("/") + 1));
                    System.Web.HttpContext.Current.Cache.Insert(CacheKey, ds, null, DateTime.Now.AddMinutes(i), TimeSpan.Zero);
                }
                else
                    ds = (DataSet)System.Web.HttpContext.Current.Cache[CacheKey];
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    PageKeyWord.Append(dr["Title"].ToString() + "-" + dr["KeyWord"].ToString() + "-" + dr["Contents"].ToString());
                }
                if (string.IsNullOrEmpty(PageKeyWord.ToString()))
                    PageKeyWord.Append("科技");
            }
            catch
            {
                PageKeyWord.Append("科技");
            }
            return PageKeyWord.ToString();
        }

        /// <summary>
        /// 获取页面关键字数据源
        /// </summary>
        /// <param name="PageName">页面名称</param>
        /// <returns></returns>
        public DataSet GetKeyWordData(string PageName)
        {
            return HHDBUtility.DbHelperSQL.Query("Select top 1 * from V_PageKeys with(nolock) where PageName='" + PageName + "' order by Sort desc,CreateTime desc");
        }
        #endregion
    }
}
